package com.sun.hilt;

import android.util.Log;

import com.sun.hilt.impl.BindElectricEngine;
import com.sun.hilt.impl.BindGasEngine;
import com.sun.hilt.inter.Engine;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;


public class Truck{

    private Computer computer1;
    private Computer computer2;

    private List<Computer> mCargos;
    private Driver mDriver;

    @BindGasEngine
    @Inject
    public Engine mEngine;

    @BindElectricEngine
    @Inject
    public  Engine electricEngine;


//    @Inject
    public Truck() {
        computer1 = new Computer("computer 1");
        computer2 = new Computer("computer 2");
        mCargos = new ArrayList<>();
    }

    @Inject
    public Truck(Driver driver) {
        mDriver = driver;
        mCargos = new ArrayList<>();
    }

    public boolean addCargo(Computer computer) {
        return mCargos.add(computer);
    }

    public boolean deliverReal() {
        for(Computer computer : mCargos) {
            loadToTruck(computer);
        }
        return beginToDeliver(mDriver);
    }

    public boolean deliver() {
        loadToTruck(computer1);
        loadToTruck(computer2);
        return beginToDeliver(null);
    }

    private void loadToTruck(Computer computer) {
        Log.d("syp","装箱电脑：" + computer.getComputerName());
    }

    private boolean beginToDeliver(Driver driver) {
        electricEngine.start();
        Log.d("syp","开始配送:" + (driver == null ? "" : driver.toString()));
        electricEngine.shutDown();
        return true;
    }


}
